﻿Public Class CShiporderState2 : Inherits CStateBase

    ''' <summary>
    ''' 実行可能かを判断する
    ''' </summary>
    ''' <param name="task"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function IsEnter(ByVal task As CTaskBase) As Boolean
        Debug.WriteLine("CShiporderState2.IsEnter")
        If CCommon.isInStr(task.ActionCd, "SHIPTOLABEL") Then
            Return True
        Else
            Return False
        End If
    End Function

    ''' <summary>
    ''' 実行メソッド
    ''' </summary>
    ''' <param name="task"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function DoExecute(ByVal task As CTaskBase) As CStateBase
        Dim nextState As CStateBase
        Dim pdaTask As CPDATask2 = DirectCast(task, CPDATask2)
        Debug.WriteLine("CShiporderState2.DoExecute")
        Dim checkInfo As CCheck = CCheck.GetIns
        Dim AppManager As CApplicationManager = CApplicationManager.GetInstance
        Dim webMng As CWebManager = CWebManager.GetInstance


        If task.ProcessText = "" Then
            '' リーダーからデータを取得する(待ち時間制限なし)
            pdaTask.WindowManager.SetMessage(CConst.CNS_MSG_010, CConst.COLOR_BLACK, CConst.COLOR_GREEN)
            task.ProcessText = task.ReadTextWait(-1)
            Debug.WriteLine("読んだバーコード:" & task.ProcessText)
        End If
        Debug.WriteLine("CShiporderState2...START")

        Select Case CBarcode.GetBarcodeType(task.ProcessText)

            '総統括コード
            Case EnumBarcodeType.GROUP_REPORT_CODE, EnumBarcodeType.REPORT_CODE

                Debug.WriteLine("総統括コードを読みました。")
                pdaTask.WindowManager.SetMessage(CConst.CNS_MSG_011, CConst.COLOR_BLACK, CConst.COLOR_GREEN)

                Select Case webMng.getShiporderData(pdaTask, task.ProcessText)
                    '成功
                    Case 0
                        task.ActionCd = "LABELCHECK"
                        pdaTask.Hardware.nextA()
                        '警告
                    Case 1
                        task.ActionCd = "LABELCHECK"
                        pdaTask.Hardware.nextA()
                        'エラー, '警告
                    Case 99, 2
                        task.ProcessText = ""
                        task.ActionCd = "SHIPTOLABEL"
                        Return DoBaseExecute(task)
                End Select

                '交代
            Case EnumBarcodeType.EMP_CODE

                Dim EmpData As CCheck.EmpData = checkInfo.ChkEmpData(task.ProcessText)

                pdaTask.WindowManager.SetEmpInfo(EmpData.empCd & ":[" & EmpData.empName & "]") '
                pdaTask.EmpCd = EmpData.empCd
                task.ActionCd = "SHIPTOLABEL"

            Case Else
                task.ProcessText = ""
                CPersonal.ErrorWindow2(pdaTask, EnumWindowMode.ALERT_MODE, _
                                        Color.Black, CConst.EnumSound.ALERT_BUZZ, CConst.CNS_MSG_023, Color.White)
                task.ActionCd = "SHIPTOLABEL"


        End Select

        task.ProcessText = ""
        nextState = GetNextState(task)
        Debug.WriteLine("CShiporderState2...END")

        Return nextState
        '注文番号存在チェッ
    End Function

    ''' <summary>
    ''' 終了メソッド(未使用)
    ''' </summary>
    ''' <param name="task"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function DoExit(ByVal task As CTaskBase) As Boolean
        Debug.WriteLine("CCANCELLabelState.DoExit")
        Return True
    End Function


End Class
